package com.kele.single;

import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;

/**
 * @author kele
 * @date 2021/10/13 16:13
 * @description
 *
 * 枚举实现单例
 */
public enum EnumSingle {
    INSTANCE;

    public EnumSingle getInstance(){
        return INSTANCE;
    }


}

class Test{
    public static void main(String[] args) throws NoSuchMethodException, InvocationTargetException, InstantiationException, IllegalAccessException {
        EnumSingle single1 = EnumSingle.INSTANCE;
        EnumSingle single2 = EnumSingle.INSTANCE;

        Constructor<EnumSingle> declaredConstructor = EnumSingle.class.getDeclaredConstructor(String.class, int.class);
        declaredConstructor.setAccessible(true);
        EnumSingle single3 = declaredConstructor.newInstance(null);
        System.out.println(single3);
        System.out.println(single1==single2);
    }
}
